<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"
	import="com.yh.news.biz.*,com.yh.news.entity.*,java.util.*"%>
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>新闻列表</title>
<link rel="stylesheet" href="css/bootstrap.min.css">
<script src="js/jquery-3.1.1.js"></script>
<script src="js/bootstrap.min.js"></script>
</head>
<body>

	<%
		/*Object obj = session.getAttribute("news");
		List<News> list = null;
		Page p;
		if (obj == null) {
			response.sendRedirect("donews.do?opt=find");//交给处理页处理
			return;
		} else {
			p = (Page) obj;
			list = p.getPageList();//当前页集合
			session.removeAttribute("news");//保证每次得到新的集合
		}*/
	%>

	<c:if test="${empty page }">

		<jsp:forward page="donews.do?opt=find"></jsp:forward>

	</c:if>

	<form id="f" class="form-inline" role="form" action="donews.do?opt=find&ex=search" method="post">
		<div class="form-group">
			<label class="sr-only" for="name">标题</label> <input type="text"
				class="form-control" id="name"  name="title" placeholder="标题" value="${param.title }">
		</div>
		<div class="form-group">
			<label class="sr-only" for="name">内容</label> <input type="text"
				class="form-control" id="name" name="content" value="${param.content }" placeholder="内容">
		</div>

        <input type="hidden" name="i" id="index" value="1"/>
		<button type="submit" class="btn btn-default">查询</button>
	</form>
	<table class="table table-bordered">
		<caption>新闻列表</caption>
		<thead>
			<tr>
				<th>标题</th>
				<th>作者</th>
				<th>创建时间</th>
				<th>操作</th>
			</tr>
		</thead>
		<tbody>
			<c:forEach items="${page.pageList }" var="n">
				<tr>
					<td>${n.ntitle }</td>
					<td>${n.nauthor }</td>
					<td>${n.ncreateDate }</td>
					<td><a href="news_read.jsp?id=${n.nid}">详情</a>&nbsp;&nbsp;<a
						href="news_update.jsp?id=${n.nid}">修改</a>&nbsp;&nbsp;<a
						href="javascript:void(0);" onclick="del(${n.nid});">删除</a></td>
				</tr>
			</c:forEach>

		</tbody>
	</table>
	<a href="news_add.jsp">添加</a>
	<div style="float: right;">
		[${page.pageIndex }/${page.pageTotal }]

		<c:if test="${page.pageIndex gt 1 }">
			<a href="javascript:void(0);" onclick="dosubmit(1);">首页</a>
			<a href="javascript:void(0);" onclick="dosubmit(${page.pageIndex-1 });">上一页</a>
		</c:if>

		<c:if test="${page.pageIndex lt page.pageTotal }">
			<a href="javascript:void(0);" onclick="dosubmit(${page.pageIndex+1 });">下一页</a>
			<a href="javascript:void(0);" onclick="dosubmit(${page.pageTotal });">末页</a>
		</c:if>




	</div>
</body>
</html>
<script>
  function dosubmit(i){//页码
	  document.getElementById("index").value=i;//表单中隐藏域
	  document.getElementById("f").submit();//表单提交
  }



  function del(id){
	 var f= confirm("确定要删除吗？");
	 if(f){
		 location.href="donews.do?opt=del&id="+id;
	 }
  }

</script>
<c:remove var="page" />